import __builtin__

from client.towersystem.tower import Tower
from server.sessionstuff.webentities import webtower
from client.utils import assethandling


def get_tower_data(name):
    if name == "HighTower":
        return TowerData("HighTower", 100, 8, 1.1, 40, 0.5, 30, [], 2, "Bullet", 3)
    if name == "TestTower":
        return TowerData("TestTower",  120, 5, 0.7, 10, 0.5, 20, ["HighTower", "FatTower"], 2, "Bullet", 3)
    if name == "FatTower":
        return TowerData("FatTower", 300, 4, 0.4, 8, 0.5, 25, [], 3, "Bullet", 5)


def create_tower(name):
    data = get_tower_data(name)
    tower = Tower(name, assethandling.createTower(), data.hp, data.range, data.atkspeed, data.damage, data.radius, data.cost, data.upgrades)
    if name == "FatTower":
        tower.towerNode.setScale(1.4, 1.4, 0.9)
    if name == "HighTower":
        tower.towerNode.setScale(0.8, 0.8, 2.5)
    return tower


def create_web_tower(name):
    data = get_tower_data(name)
    tower = webtower.WebTower(name, data.hp, data.range, data.atkspeed, data.damage, data.radius, data.cost, data.upgrades, data.worth, data.projectile, data.aggro)
    return tower


def _get_model(name):
    model = 0
    if name == "HighTower" or name == "TestTower" or name == "FatTower":
        model = __builtin__.loader.loadModel("models/panda-model")
        model.setScale(0.005, 0.005, 0.005)
    return model


class TowerData():

    def __init__(self, name, hp, range, atkspeed, damage, radius, cost, upgrades, worth, projectile, aggro):
        self.name = name
        self.atkspeed = atkspeed
        self.radius = radius
        self.hp = hp
        self.range = range
        self.damage = damage
        self.worth = worth
        self.upgrades = upgrades
        self.cost = cost
        self.worth = worth
        self.projectile = projectile
        self.aggro = aggro
